package com.lukebang.service.serviceImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Service;

import com.lukebang.constant.Const;
import com.lukebang.dao.GoodDAO;
import com.lukebang.dao.GoodSpecialDAO;
import com.lukebang.dao.MeasureIndentDAO;
import com.lukebang.pojo.MeasureIndent;
import com.lukebang.pojo.Merchant;
import com.lukebang.service.IExportService;
import com.lukebang.util.export.excel.ExcelDto;
import com.lukebang.util.export.excel.IndentExcelUtil;

/**
 * 
 * ExportServiceImpl 上午11:15:51
 * 
 * Copyright zhaocj Inc. All rights reserved.
 * Love ME Like Justin Bieber.
 */
@Service("exportService")
public class ExportServiceImpl implements IExportService {
	@Resource
	MeasureIndentDAO measureIndentDAO;
	@Resource
	GoodDAO goodDAO;
	@Resource
	GoodSpecialDAO goodSpecialDAO;

	/**
	 * 导出订单固定格式 订单号/订单类型/下单人 /下单手机号/下单时间/顾客姓名/顾客手机号/顾客地址/订单价格/安心保选择/加价金额
	 * 
	 * 
	 * 
	 */
	@Override
	public void selectIndentForExportExcel(HttpServletRequest request, HttpSession session,
			HttpServletResponse response, Integer type, Integer status, String beginTime, String endTime) {
		Merchant merchant = (Merchant) session.getAttribute(Const.SESSION_USER);
		Map<String, Object> retsMap = new HashMap<String, Object>();
		retsMap.put("total", 0);
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("offset", 0);
		queryMap.put("limit", 100);
		queryMap.put("sort", "indentID");
		queryMap.put("order", "desc");
		queryMap.put("subscribeTimeBegin", beginTime);
		queryMap.put("subscribeTimeEnd", endTime);
		queryMap.put("indentStatus", status);
		queryMap.put("merchantID", merchant.getMerchantsId());
		List<MeasureIndent> indentByMerchant = measureIndentDAO.selectMeasureIndentByMerchant(queryMap);
		if (indentByMerchant.size() != 0) {
			try {
				List<ExcelDto> excelDtos = IndentExcelUtil.measureIndent2ExcelDtos(indentByMerchant,goodDAO,goodSpecialDAO);
				IndentExcelUtil.xlsDto2Excel(excelDtos, response);
				System.out.println(excelDtos.size());
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

}
